import request from '../plugin/axios'

export function login(data: { mobile: string; pwd: string }){
    return request({
        url:'v1/agent/login',
        method:'post',
        data
    })
}

export function updatePassword(data:any):Promise<any>{
    return request({
        url:'v1/agent/password/edit',
        data,
        method:'post'
    })
}

export function loginByMobile(data: { mobile:string; sms_code:string }){
    return request({
        url:'/smsLogin',
        method:'post',
        data
    })
}

export function sendLoginCaptcha(data: { mobile:string }){
    return request({
        url:'/loginSmsCode',
        method:'post',
        data
    })
}

export function sendRegisterCaptcha(data: { mobile:string }){
    return request({
        url:'/registerSmsCode',
        method:'post',
        data
    })
}

export function validRegisterCaptcha(data: {mobile:string; sms_code:string}) {
    return request({
        url:'/registerSmsCodeVerify',
        data,
        method:'post'
    })
}

export function register(data: { 
    mobile:string;
    password:string;
    confirm_password:string;
    company_name:string
}){
    return request({
        url:'/register',
        data,
        method:'post'
    })
}

export function getMenu():Promise<any>{
    return request({
        url:'v1/agent/valid/menu/list',
        method:'get'
    })
}

export function logout(){
    return request({
        url:'v1/agent/logout',
        method:'post'
    })
}

export function getDict(){
    return request({
        url:'/v1/config/get',
        method:'get'
    })
}

export function getPermissions(){
    return request({
        url:'/permissions',
        method:'post'
    })
}

export function getUserinfo():Promise<any>{
    return request({
        url:'v1/agent/info/get'
    })
}

export function getConfig():Promise<any>{
    return request({
        url:'v1/config/get'
    })
}

export function getRegion(params:{
    parent_id?:any
}):Promise<any>{
    return request({
        url:'v1/tools/region/get',
        params,
        method:'get'
    })
}

export function getProvinces():Promise<any> {
    return request({
        url:'/district/getProvinces',
        method:'post'
    })
}

export function getCities(data:{
    province_id:number
}):Promise<any>{
    return request({
        url: `/district/getCities/${data.province_id}`,
        data,
        method: 'post'
    })
}

export function getDistrictes(data:{
    city_id:number
}):Promise<any>{
    return request({
        url: `/district/getDistricts/${data.city_id}`,
        data,
        method: 'post'
    })
}

export function saveAccount(data:{
    tenant_name:string | undefined,
    contact_name: string,
    province_id: number | undefined,
    city_id:number | undefined,
    district_id:number | undefined,
    address_detail:string
}):Promise<any>{
    return request({
        url: `/user/editTenant`,
        data,
        method:'post'
    })
}


export function getPayInfo(params:{
    level_id: number
}):Promise<any>{
    return request({
        url:`/tenantPurchase/purchasePackage/${params.level_id}`,
        params,
        method:'get'
    })
}

export function getPayState(params:{
    purchase_id: number
}):Promise<any>{
    return request({
        url:`/tenantPurchase/payStatus/${params.purchase_id}`,
        params,
        method:'get'
    })
}

export function pay(data:{
    package_id:number,
    pay_type:number,
    pay_fee:number
}):Promise<any>{
    return request({
        url:`/tenantPurchase/purchase`,
        data,
        method:'post'
    })
}

export function getMyOrderList(data:{
    start_create_at: string,
    end_create_at:string,
    current_page:number,
    size:number
}):Promise<any>{
    return request({
        url:'/tenantPurchase/myList',
        data,
        method:'post'
    })
}

export function createOrder(data: {
    package_id: number,
    pay_type: number,
    pay_fee: number
}):Promise<any>{
    return request({
        url:'/tenantPurchase/purchase',
        data,
        method:'post'
    })
}

export function cancelOrder(data: {
    id:number
}):Promise<any>{
    return request({
        url:'/tenantPurchase/cancel',
        data,
        method:'post'
    })
}

export function getMyInvoiceTitle():Promise<any>{
    return request({
        url:'/tenantAddValueTax/myList',
        method:'get'
    })
}

export function saveMyInvoiceTitle(data: {
    id?: number | undefined | null,
    invoice_header: string,
    unit_tax_no:string,
    reg_address:string,
    reg_tel: string,
    open_bank: string,
    bank_account: string,
    tax_status: number | undefined | null,
    audit_at: string,
    create_at: string,
    account:string,
    tax_status_desc:string
}):Promise<any>{
    return request({
        url:'/tenantAddValueTax/save',
        method:'post',
        data
    })
}

export function discardMyInvoiceTitle(data: {
    id:number
}):Promise<any>{
    return request({
        url:'/tenantAddValueTax/discard',
        method:'post',
        data
    })
}

export function getInvoiceTitle(params:{
    purchase_id:number
}):Promise<any>{
    return request({
        url:`/tenantInvoice/saveInfo/${params.purchase_id}`,
        method:'get',
        params
    })
}

export function getInvoiceDetail(params:{
    id:number
}):Promise<any>{
    return request({
        url:`/tenantInvoice/myDetail/${params.id}`,
        params,
        method:'get'
    })
}

export function saveInvoice(data:{
    id:number,
    purchase_id:number,
    content:string,
    amount:string,
    invoice_type:number,
    invoice_header:string,
    unit_tax_no:string,
    reg_address:string,
    reg_tel:string,
    open_bank:string,
    bank_account:string,
    email:string
}):Promise<any>{
    return request({
        url:'/tenantInvoice/save',
        data,
        method:'post'
    })
}

export function getSellerList(params:any):Promise<any>{
    return request({
        url:'v1/tools/seller/list',
        params,
        method:'get'
    })
}